package twentyOne;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 锁测试
 *
 * @author MSI PC
 * @since 2020-04-26 09:36
 */
public class demo01 {


    static Lock lock = new Lock();

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.execute(()->{

            lock.printSthLocked();
            try {
                TimeUnit.SECONDS.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });


        lock.printSthLocked();

    }





}



class Lock {

    public synchronized void printSthLocked(){
        System.out.println("some one use locked function !");
    }

    public void printSth(){
        System.out.println("some one use function !");
    }

}


class useLock1{
    public void oneUse(){
        Lock lock = new Lock();
        lock.printSthLocked();
    }

}


class useLock2{
    public void oneUse(){
        Lock lock = new Lock();
        lock.printSthLocked();
    }

}